#include "../apue.h"
#include <sys/wait.h>

#ifdef SOLARIS
#define PSCMD "ps -a -o pid,ppid,s,tty,comm"
#else
#define PSCMD "ps -o pid,ppid,state,tty,command"
#endif

int main(void)
{
    pid_t pid;

    TELL_WAIT();

    if ((pid = fork()) < 0)
        err_sys("fork error");
    else if (pid == 0)
    {
        printf("child pid: %d(ppid:%d)\n", getpid(), getppid());
        TELL_PARENT(getppid());
        _exit(0);
    }

    WAIT_CHILD();
    printf("parent pid: %d\n", getpid());

    if (system(PSCMD) < 0)
        err_sys("system() error");

}
